package com.lanou.renrenxin.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import com.easemob.chat.EMChat;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseUser;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zy on 16/2/29.
 */
public class BaseApplication extends Application {
    private static Context context;
    public static List<Activity> activities;
    public final static int LOGIN_SUCCESS = 100;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        BaseApplication.context = this;
        EMChat.getInstance().init(context);
        //服务器
//        Parse.enableLocalDatastore(this);
//        // Enable Local Datastore.
        Parse.enableLocalDatastore(this);

        // Add your initialization code here
        Parse.initialize(this);

        ParseUser.enableAutomaticUser();
        ParseACL defaultACL = new ParseACL();
//        // Optionally enable public read access.
//        // defaultACL.setPublicReadAccess(true);
        ParseACL.setDefaultACL(defaultACL, true);

/**
 * debugMode == true 时为打开，sdk 会在log里输入调试信息
 * @param debugMode
 * 在做代码混淆的时候需要设置成false
 */
        EMChat.getInstance().setDebugMode(true);//在做打包混淆时，要关闭debug模式，避免消耗不必要的资源
    }

    public static Context getContext() {
        return BaseApplication.context;
    }
    //封装log

    //添加所有Activity
    public static void addActivity(Activity activity) {
        if (activities == null) {
            activities = new ArrayList<>();
        }
        activities.add(activity);
    }

    public static void removeActivity(Activity activity) {
        activities.remove(activity);

    }

    //结束所有activity
    public static void finishAllActivity() {
        for (Activity activity : activities) {
            activity.finish();
        }

    }


}
